<!--
 * @Date: 2022-03-26 09:53:00
 * @LastEditors: sailornpg
 * @LastEditTime: 2022-03-26 12:47:25
 * @FilePath: \vue3Components\src\components\menu\Mymenu.vue
 * @Description: something
-->
<template>
  <el-menu
    class="el-menu-vertical-demo"
    :default-active="defaultActive"
    :router="router"
    v-bind="$attrs"
  >
    <template v-for="(item, i) in data" :key="i">
      <el-menu-item v-if="!item.children || !item.children.length" :index="item.index">
        <component
          v-if="item.icon"
          :is="`el-icon-${toLine(item.icon)}`"
          style="width: 1em; height: 1em; margin-right: 5px;"
        ></component>
        <span>{{ item.name }}</span>
      </el-menu-item>
      <el-sub-menu v-if="item.children && item.children.length" :index="item.index">
        <template #title>
          <component
            v-if="item.icon"
            :is="`el-icon-${toLine(item.icon)}`"
            style="width: 1em; height: 1em; margin-right: 5px;"
          ></component>
          <span>{{ item.name }}</span>
        </template>
        <el-menu-item v-for="(item1, index1) in item.children" :key="index1" :index="item1.index">
          <component
            v-if="item1.icon"
            :is="`el-icon-${toLine(item1.icon)}`"
            style="width: 1em; height: 1em; margin-right: 5px;"
          ></component>
          <span>{{ item1.name }}</span>
        </el-menu-item>
      </el-sub-menu>
    </template>
  </el-menu>
</template>
 <script lang='ts' setup>
import { MenuItem } from './type';
import { PropType } from 'vue'
import { toLine } from '../../utils';
const props = defineProps({
  data: {
    type: Array as PropType<MenuItem[]>,
    required: true
  },
  defaultActive: {
    type: String,
    default: ''
  },
  router: {
    type: Boolean,
    default: false
  },
})
</script>
<style lang='less' scoped>
</style>